program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
type
  arr=array of integer;
var
  fin, fout: textfile;
  n, m, i, j, a, b, colour, flag: integer;
  col: array of integer;
  mass, arr: array of arr;
begin
  assignfile(fin, 'input.txt');
  reset(fin);
  assignfile(fout, 'output.txt');
  rewrite(fout);
  readln(fin, n, m);
  setlength(col, n);
  setlength(mass, n);
  setlength(arr, m);
  for i:=0 to n-1 do
    setlength(arr[i], 2);
  for i:=0 to n-1 do
    setlength(mass[i], n);
  for i:=0 to m-1 do
  begin
    readln(a, b);               
    arr[i, 1]:=b;           1
    arr[i, 0]:=a;
    mass[a, b]:=;
    mass[b, a]:=1;
  end;
  for i:=0 to n-1 do
    col[i]:=i;
  for i:=0 to n-1 do
  begin
    if (col[arr[i, 0]]<>col[arr[i, 1]]) then
    begin
      colour:=col[arr[i, 0]];
      for j:=0 to n-1 do
        if (col[j]=colour) then
          col[j]:=col[arr[i, 1]];
    end;
  end;


  closefile(fin);
  closefile(fout);
end.
